package com.unimas.dof.render;

import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import com.unimas.dof.DOFContext;
import com.unimas.dof.view.BinaryView;

public class BinaryRender implements DOFRender<BinaryView> {

	public void render(BinaryView view, DOFContext context) throws Exception {
		String filename = new String(view.getFileName().getBytes("GBK"), "ISO8859_1");
		HttpServletResponse response = context.getResponse();
		
		if(view.getContentType() != null){
			response.setContentType(view.getContentType());
		}
		response.setContentLength(view.getData().length);
		response.setHeader("Content-Disposition", "attachment;filename=" + filename);
		response.setContentType("application/octet-stream");

		OutputStream out = response.getOutputStream();
		out.write(view.getData());
		out.close();
	}

}
